﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

// Condition: Write a program that sinds in given array of integers a
//            sequence of given sum S( if present).

class SeqByGivenSum
{
    static void Main()
    {
        // 1. Declare Given Sum, elements of array and helping variables
        Console.Write("Enter sum you want to check if presented: ");
        int S = int.Parse(Console.ReadLine());
        Console.Write("Enter number of elements N: ");
        int N = int.Parse(Console.ReadLine());
        int[] myArr = new int[N];
        Console.WriteLine("Enter elements of integer array: ");
        for (int index = 0; index < N; index++)
        {
            Console.Write("element[{0}]= ", index);
            myArr[index] = int.Parse(Console.ReadLine());
        }
        int sum = 0;
        bool check = false;
        int start = -1;
        int end = -1;

        // 2. check is there a sum equal to given S

        for (int i = 0; i < myArr.Length; i++)
        {
            sum = 0;
            for (int j = i; j < myArr.Length; j++)
            {
                sum = sum + myArr[j];

                if (sum == S)
                {
                    check = true;
                    start = i;
                    end = j;
                }
            }

        }

        // 3. Print the result

        if (check == false)
        {
            Console.WriteLine("There is no sequence which sum={0}", S);
        }
        else
        {
            Console.Write("The sequence which sum={0} is: ",S);
            Console.Write("{");
            for (int k = start; k <= end; k++)
            {
                Console.Write(myArr[k] + " ");
            }
            Console.Write("}");
        }
        Console.WriteLine();
    }
}

